import Vue from 'vue'
import App from './App'
import store from './store/store.js'
//导入网络请求包
import {$http} from "@escook/request-miniprogram"

uni.$http = $http
// 请求根路径
$http.baseUrl = 'https://api-ugo-web.itheima.net'
//请求拦截器（请求之前的Loading效果）
$http.beforeRequest = function(option){
	uni.showLoading({
		title:"数据加载中"
	})
	// 判断当前请求为有权限的接口
	if(option.url.indexOf('/my/') != -1) {
		option.header = {
			"Authorization":store.state.my_user.token
		}
	}
	console.log(store.state.my_user.token);
},
//响应拦截器（请求之后的Loading效果隐藏）
$http.afterRequest = function(option){
	uni.hideLoading()
}

uni.$showMsg = function(title="数据请求失败！",duration=1500){
	uni.showToast({
		title,
		duration,
		icon:"none"
	})
}

Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
	...App,
	store
})
app.$mount()
